const {app, BrowserWindow,ipcMain} = require('electron');
const path = require('path');
const fs = require('fs');

function writeFile(_,data){
    fs.writeFileSync('D:/hello.txt',data);
}

function readFile(){
    let s = fs.readFileSync('D:/hello.txt').toString();
    console.log('####',s)
    return  s;
}

function createWindow() {
    const win = new BrowserWindow({
            width: 800,
            height: 600,
            autoHideMenuBar: true,
            webPreferences: {
                preload:path.resolve(__dirname, 'preload.js'),
            }
        }
    );

    // win.loadURL('http://www.atguigu.com');
    ipcMain.on('save-file', writeFile)
    ipcMain.handle('read-file', readFile);
    win.loadFile('./pages/index.html');
}

// app.whenReady().then(() => {
//     console.log(6666)
// });

// console.log(process.version);


// 下面的写法和上面的一样
app.on('ready', () => {
    console.log('应用准备好了')
    createWindow();
    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0) createWindow()
    })

})

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') app.quit()
})



